<?php
    //查出顶级分类
    $sql = "select cname,id,path from ".PRE."category where pid = 0";
    $cate_list = query($link,$sql);
?>

<?php if(!empty($cate_list)):?>
    <?php foreach($cate_list as $value):?>
        <li class="dropdown">
            <a href="<?php echo ROOT_URL?>category_goods.php?id=<?php echo $value['id']?>&path=<?php echo $value['path']?>" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><?php echo $value['cname']?><span class="caret"></span></a>
            <?php
                 //查询顶级分类的下一级分类
                $sql = "select cname,id,pid,path from ".PRE."category where path = '".$value['path'].$value['id'].",'";
                 $cate_list_1 = query($link, $sql);
            ?>
            <ul  class="dropdown-menu" aria-labelledby="dropdownMenu1">
                <?php if(!empty($cate_list_1)):?>
                    <?php foreach($cate_list_1 as $value_1):?>
                        <li><a href="<?php echo ROOT_URL?>category_goods.php?id=<?php echo $value_1['id']?>&path=<?php echo $value_1['path']?>&pid=<?php echo $value_1['pid']?>"><?php echo $value_1['cname']?></a></li>
                    <?php endforeach;?>
                <?php endif;?>
            </ul>

    <?php endforeach;?>
<?php endif;?>
